package com.dahuyou.tryy.too.simulate.interpreter.runtime.area;

import com.dahuyou.tryy.too.simulate.interpreter.runtime.area.heap.methodarea.Method;

public class Thread {

    // 程序计数器 program counter
    private int pc;

    // 线程虚拟机栈，每个线程都会被分配这样的一块内存区域
    private JvmStack stack;

    public Thread(){
        this.stack = new JvmStack(1024);
    }

    public void setStack(JvmStack stack) {
        this.stack = stack;
    }

    public int pc(){
        return this.pc;
    }

    public void setPC(int pc){
        this.pc = pc;
    }

    public void pushFrame(Frame frame){
        this.stack.push(frame);
    }

    public Frame popFrame(){
        return this.stack.pop();
    }
    public boolean isStackEmpty(){
        return this.stack.isEmpty();
    }

    public Frame topFrame(){
        return this.stack.top();
    }

    public Frame currentFrame(){
        return this.stack.top();
    }

    public Frame newFrame(Method method) {
        return new Frame(this, method);
    }

    public Frame newFrame(int maxLocals, int maxStack) {
        return new Frame(this, maxLocals, maxStack);
    }

}
